<%@page import="domain.ContactGroup"%>
<%@page import="domain.Entreprise"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="domain.Contact" %>
    <%@ page import="domain.PhoneNumber" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" media="screen, projection" href="scripts/demo.css" />
<script type="text/javascript" src="scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="scripts/validation.js"></script>
<title>Modification Contact</title>
</head>
<body>
	<% Contact contact = (Contact)request.getAttribute("contact");
		PhoneNumber p1 = (PhoneNumber)contact.getPhones().toArray()[0];
		PhoneNumber p2 = new PhoneNumber();
		PhoneNumber p3 = new PhoneNumber();
		if(contact.getPhones().toArray().length>1){
			p2 = (PhoneNumber)contact.getPhones().toArray()[1];
		}
		else p2.setPhoneNumber("");
		if(contact.getPhones().toArray().length>2)
			p3 = (PhoneNumber)contact.getPhones().toArray()[2];
		else p3.setPhoneNumber("");
	%>
	<form action="EditContact" method="post" onsubmit="return validateFormAdd()">
	<br><br>
	<table align="center" bgcolor="green" id="containerAddContact">
	<tr>
		<td align="right">Group : </td><td colspan="2">
		<%boolean hasFriend = false;
		boolean hasFamily = false;
		boolean hasColleague = false;
		
		for(ContactGroup cg : contact.getBooks()){ 
			
			if(cg.getGroupName().equals("Friend")) hasFriend=true;
			else if(cg.getGroupName().equals("Family")) hasFamily = true;
			else if(cg.getGroupName().equals("Colleague")) hasColleague=true;}
		
			if(hasFriend){%>
		<input name="friendChk" type="checkbox" value="Friend" checked="checked"/>Friend
			<%}else{%>
		<input name="friendChk" type="checkbox" value="Friend"/>Friend
			<%}if(hasFamily){%>
		<input name="familyChk" type="checkbox" value="Family" checked="checked"/>Family
			<%}else{%>
		<input name="familyChk" type="checkbox" value="Family"/>Family
			<%}if(hasColleague){%>
		<input name="colleagueChk" type="checkbox" value="Colleague" checked="checked"/>Colleague
			<%}else{%>
		<input name="colleagueChk" type="checkbox" value="Colleague"/>Colleague
			<%} for(ContactGroup cg : contact.getBooks()){ 
			if(!(cg.getGroupName().equals("Friend")| cg.getGroupName().equals("Family") | cg.getGroupName().equals("Colleague"))){%>
		<input name="<%= cg.getGroupName()%>Chk" type="checkbox" value="<%= cg.getGroupName()%>"/><%= cg.getGroupName()%>
			<%} }%>
		</td>
	</tr>
	<tr>
	<td>Other group </td><td><input type="text" name="other"/> </td>
	</tr>
	<tr>
		<td align="right">First name* : </td><td><input type="text" id="firstname" name="firstname" value="<%=contact.getFirstName()%>"></td><td><label id="lbCheckFirstName" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Last name* : </td><td><input type="text" id="lastname" name="lastname" value="<%=contact.getLastName()%>"></td><td><label id="lbCheckLastName" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Email* : </td><td><input type="text" id="email" name="email" value="<%=contact.getEmail()%>"></td><td><label id="lbCheckEmail" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Street* : </td><td><input type="text" id="street" name="street" value="<%=contact.getAddress().getStreet()%>"></td><td><label id="lbCheckStreet" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">City* : </td><td><input type="text" id="city" name="city" value="<%=contact.getAddress().getCity()%>"></td><td><label id="lbCheckCity" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Zip code* : </td><td><input type="text" id="zip" name="zip" value="<%=contact.getAddress().getZip()%>"></td><td><label id="lbCheckZip" style="color: red;"></label></td>
	</tr>
	<tr>
		<td align="right">Telephone* : </td><td><input type="text" id="phone1" name="phone1" value="<%=p1.getPhoneNumber()%>">
		<select id="phonetype1" name="phonetype1">
		<option value="Mobile" selected="selected">Mobile</option>
    	<option value="Fix">Fix</option>
		</select></td>
		<td><label id="lbCheckPhone1" style="color: red;"></label></td>
	</tr>
	<tr>
		<td></td><td><input type="text" id="phone2" name="phone2" value="<%=p2.getPhoneNumber()%>">
		<select id="phonetype2" name="phonetype2">
		<option value="Mobile" selected="selected">Mobile</option>
    	<option value="Fix">Fix</option>
		</select></td>
	</tr>
	<tr>
		<td></td><td><input type="text" id="phone3" name="phone3" value="<%=p3.getPhoneNumber()%>">
		<select id="phonetype3" name="phonetype3">
		<option value="Mobile" selected="selected">Mobile</option>
    	<option value="Fix">Fix</option>
		</select></td>
	</tr>
	<%if(contact instanceof Entreprise){%>
	<tr>
		<td align="right" id="lbsiret">SIRET Number* : </td>
		<td><input type="text" id="siret" name="siret" value="<%=((Entreprise)contact).getNumSiret()%>"></td>
	</tr>
	<%} %>
	<tr>
		<td></td><td><input type="submit" value="Update">  <input type="reset" value="Reset"></td>
	</tr>
	
	</table> 
	</form>
</body>
</html>